353B - Two Heaps - CodeForces Solution


combinatorics constructive algorithms greedy implementation math sortings *1900

Please click on ads to support us..

Python Code:

def s():
        input()
        l = [[] for _ in range(100)]
        a = list(map(int, input().split()))
        for (i, v) in enumerate(a):
                l[v].append(i)
        c = 0
        cc = 0
        fs = [0, 0]
        for i in l:
                if len(i) == 0:
                        continue
                if len(i) == 1:
                        a[i[0]] = c + 1
                        fs[c] += 1
                        c = 1 - c
                        continue
                fs[c] += 1
                fs[c - 1] += 1
                for e in i[:len(i) // 2]:
                        a[e] = 1 + cc
                for e in i[len(i) // 2:]:
                        a[e] = 2 - cc
                if len(i) % 2 == 1:
                        cc = 1 - cc
        print(fs[0] * fs[1])
        print(*a)
s()


Comments

Submit
0 Comments
More Questions

Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!